package joymouse;

import java.awt.AWTException;
import java.awt.Robot;
import joymouse.logger.Error;
import joymouse.logger.Logger;
import net.java.games.input.Controller;

/**
 * The base class for all controllers, such as a mouse controller.
 *
 * @author Ben Wolsieffer
 */
public abstract class DeviceController {

    protected Controller controller;
    protected static final Robot robot;
    
    static {
        Robot robotTemp = null;
        try {
            robotTemp = new Robot();
        } catch (AWTException ex) {
            Logger.getLogger().log(Error.CANT_CREATE_ROBOT);
        }
        robot = robotTemp;
    }

    /**
     * Assigns the specified {@link Controller} (ie. joystick) to be this device
     * controller's controller.
     *
     * @param cont The controller to use
     */
    public DeviceController(Controller cont) {
        this.controller = cont;
    }

    /**
     * Updates the device controller. This method is used to define the
     * functionality of the DeviceController. The {@link Controller} is polled not
     * automatically, instead this is done by the {@link ControllerManager}
     * which is the only class that should call this method.
     */
    protected abstract void run();

    /**
     * Gets the {@link Controller} associated with this DeviceController.
     *
     * @return the 
     */
    public Controller getController() {
        return controller;
    }
}
